<template>
	<div id='system' v-loading="loading">
		<div class="content-top">
			<span class="h1">查询分析</span>
			<span class="h2">分配汇总查询</span>
		</div>
		<div class="top-btn clearfix">
			<div class="left-content">
				<span class="tip">商家分配汇总统计表</span>
			</div>
			<div class="right-search1">
				<el-input v-model="input" placeholder="输入关键词…"></el-input>
				<el-button type="primary" @click="look()" style="margin-left: 10px;">查看</el-button>
				<el-button type="primary"@click="excel()">导出excel</el-button>
			</div>
		</div>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="PName" label="名称">
			</el-table-column>
			<el-table-column prop="ManagerMan" label="联系人">
			</el-table-column>
			<el-table-column prop="ManTel" label="联系电话">
			</el-table-column>
			<el-table-column prop="DemandTotal" label="累计需求量">
			</el-table-column>
			<el-table-column prop="AllotTotal" label="累计分配量">
			</el-table-column>
			<el-table-column prop="UnAllotTotal" label="累计未分配量">
			</el-table-column>
			<el-table-column prop="UnSetAllot" label="分配未处理量">
			</el-table-column>
			<el-table-column prop="AlSetAllot" label="分配已处理量">
			</el-table-column>
		</el-table>
		<div class="pages">
			<el-pagination small :current-page="index" @current-change="handleCurrentChange" layout="prev, pager, next" :total="total" background prev-text='上一页' next-text='下一页'>
			</el-pagination>
		</div>
	</div>
</template>

<script>
	import api from '../../../api/api'
	export default {
		name: 'proAllotq',
		data() {
			return {
				loading:true,
				input: '', //搜索
				tableData: [],
				index:1,
				total:1,
			}
		},
		created() {
			this.getunallot(this.index)
		},
		methods: {
			excel(){
				this.loading = true
				this.$axios.post(api.getunallot, {
				  "Para": this.input,
				  "PageSize": 10,
				  "PageIndex": this.index-1,
				  "OrderbyString": "PName",
				  "ToExcel": true
				}).then(res => {
					if(res.data.isOK){
						if(res.data.data.ExcelResult && res.data.data.ExcelResult.isOK) {
							this.loading = false
							var urls = res.data.data.ExcelResult.data.filePath
							window.location.href = api.host+'/template/'+urls
						} else{
							this.loading = false
							this.$message.error(res.data.data.ExcelResult.msg);
						}
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			handleCurrentChange(val){
				this.index = val
				this.getunallot(this.index)
			},
			look(){
				this.index = 1
				this.getunallot(this.index)
			},
			getunallot(val) {
				this.$axios.post(api.getunallot, {
				  "Para": this.input,
				  "PageSize": 10,
				  "PageIndex": val-1,
				  "OrderbyString": "PName",
				  "ToExcel": false
				}).then(res => {
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items?res.data.data.Items:1
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>